package top.zywork.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import top.zywork.constant.CommonConstant;
import top.zywork.dos.SchoolDO;
import top.zywork.dao.SchoolDao;
import top.zywork.dto.PagerDTO;
import top.zywork.query.SchoolQuery;
import top.zywork.service.SchoolService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author
 * @since 2020-10-12
 */
@Service
public class SchoolServiceImpl extends ServiceImpl<SchoolDao, SchoolDO> implements SchoolService {

    @Override
    public SchoolDO checkSchool(Long id) {
        return baseMapper.selectOne(new QueryWrapper<SchoolDO>()
                .eq("is_active", CommonConstant.IS_ACTIVE_TRUE)
                .eq("id", id));
    }

    @Override
    public PagerDTO listAllByCondition(SchoolQuery schoolQuery) {
        List<Object> objects = baseMapper.listAllByCondition(schoolQuery);
        Long aLong = baseMapper.countByCondition(schoolQuery);
        return PagerDTO.builder().rows(objects).total(aLong).build();
    }

    @Override
    public PagerDTO listPageByCondition(SchoolQuery schoolQuery) {
        List<Object> objects = baseMapper.listPageByCondition(schoolQuery);
        Long aLong = baseMapper.countByCondition(schoolQuery);
        return PagerDTO.builder().rows(objects).total(aLong).build();
    }
}
